package org.solr.client;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class solrj {
	public static final Logger LOGGER = LoggerFactory.getLogger(solrj.class);
	static String hostport = "127.0.0.1:2181";
	public static final String CLUSTER_STATE = "/clusterstate.json";
	private static final long serialVersionUID = 1L;
	private Map<String, String> liveShards = new HashMap<String, String>();
		
	private Watcher watcher;
	
//	private Watcher createClusterStateWatchersAndUpdate(){
//		Watcher watcher = new Watcher() {
//
//			public void process(WatchedEvent event) {
//				switch (event.getType()) {
//				case NodeDataChanged:
//					LOGGER.warn("process : " + event.toString());
//					break;
//
//				default:
//					// LOGGER.warn("process : " + event.toString());
//					break;
//				}
//
//			}
//		};
//		return watcher;
//	}
	
	
	private void createClusterStateWatchersAndUpdate(String clusterStatus) {
		Watcher watcher = new Watcher() {

			public void process(WatchedEvent event) {
				switch (event.getType()) {
				case NodeDataChanged:
					LOGGER.warn("process : " + event.toString());
					break;

				default:
					// LOGGER.warn("process : " + event.toString());
					break;
				}

			}
		};
		
		try {
			ZooKeeper zkClient = new ZooKeeper(hostport, 300000, null);
			Stat stat = new Stat();
			stat = zkClient.exists(CLUSTER_STATE, watcher);
			if (stat != null){
				byte[] data = zkClient.getData(CLUSTER_STATE, true, stat);
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (KeeperException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void addDocs() {
	}


	
	
}
